package com.yanqu.road.server.cmd.activity.pasture;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PastureProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pasture.PastureModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PASTURE_USE_SKILL_ITEM, desc = "使用充能道具")
public class PastureUseSkillItemCmd extends AbstractCommand {

    int count;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PastureProto.PastureUseSkillItemReqMsg reqMsg = PastureProto.PastureUseSkillItemReqMsg.parseFrom(packet.getBytes());
        count = reqMsg.getCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        ret = player.getModule(PastureModule.class).useSkillItem(count);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0) {
            PastureProto.PastureUseSkillItemRespMsg.Builder respMsg = PastureProto.PastureUseSkillItemRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_PASTURE_USE_SKILL_ITEM, respMsg);
        }
    }
}
